import type { DictData } from "@/types/global";
import { http } from "./http";
import type { comment } from "@/types/docter/comment";
import type { myScheduling } from "@/types/myScheduling";

export type options = {
    dictValue:string
    dictLable:string
}

/**
 * 字典替换
 * @param options
 * @param value
 */
export const getDictData = (options:DictData[],value:string) =>{
    let name=""
    options.forEach(item =>{
        if(item.dictValue === value){
            name = item.dictLabel!
        }
    })
    return name;
}

export const findDict = (id:string) =>{
    return http<DictData[]>({
        method:'GET',
        url:`/system/dictData/${id}`
    })
}

//改变日期
export const getDatesubstring = (str:string) =>{
    const index = str.indexOf("周"); // 找到 "(" 的位置
    const date = str.substring(0, index); // 截取 "(" 前面的部分
    const day = str.substring(index); // 截取 "(" 以及之后的部分
    return {
        date:date,
        day:day
    }
}

//改变日期 去掉T
export const getDate = (str:string) =>{
    const index = str.replace("T"," ");
    return index
}

//计算平均star
export const getAverage = (comm: comment[]): number => {
    if (!comm || comm.length === 0) {
      return 0;
    }
    const sum = comm.reduce((total, item) => total + item.star, 0);
    return sum / comm.length;
  };

 export const geiTime = (ev:myScheduling) =>{
    const currentHour = new Date().getHours();

      if (currentHour >= 6 && currentHour < 12) {
        return ev;
      } else if (currentHour >= 12 && currentHour < 18) {
        ev.tableData[0].schedulingType[0]=""

        return ev;
      } else {
        ev.tableData[0].schedulingType[0]=""
        ev.tableData[1].schedulingType[0]=""

        return ev;
      }
 }
